/*
 * @ author madman 
 * @ use C端添加联系人
 */
const ContactModel = require('../../../models/nexmo/contact.model');
const Utils = require('../../utils');
class Contact {
    async add(ctx) {
      const _body = ctx.request.body
      const _params = Utils._params(_body)
      const result = await ContactModel.create(_params);
      if (result) {
          return ctx.success({ msg: '添加成功' });
      } else {
          return ctx.error({ msg: '添加失败' });
      }
    }
    //'dialingPrefix defaultPrice currency countryDisplayName countryCode networks createdAt updataAt'
    async list(ctx) {
      const options = {
        name: 'nexmo/contact',
        type: 'pop',
        findField: {},
        populate: 'countryId', 
        populateField: 'countryName dialingPrefix'
    }
    if (ctx.query.msisdn) {
        options.findField.msisdn = ctx.query.msisdn
    }
    let result = await Utils.getPageList(ctx, options)
    if (result) {
        return ctx.success({
            data: result,
            msg: '查询成功'
        });
    }
    }
}

export default new Contact;